<?php
//header("Content-Type: text/html; charset=UTF-8");
include "../config.php";
include "../util/functions.php";

$GLOBALS['PATH_TO_HOME']="../";

session_start();

checkUserSession();

$resultMessage="";

$mylink = mySqlOpen($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb);

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    $password0 = $_POST['password0'];
    $password1 = $_POST['password1'];
    $password2 = $_POST['password2'];

    if ($password1 != $password2) {
        $resultMessage="Новый пароль и подтвержденный пароль не идентичны";
    } else if (strlen($password1) < 6) {
        $resultMessage="Слишком короткий пароль";
    } else if (!tryLogOnUser($_SESSION['session_user'], $password0)) {
        $resultMessage="Вы ввели неверный текущий пароль";
    } else {
        changePassword($_SESSION['session_user'], $password1);
        $resultMessage="Пароль успешно изменен";
    }
}
mySqlClose($mylink);

?>
<html>
<head>
<title>ООО "СитиМолПроект" - Современные технологии строительства и проэктирования- Главная</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="Современные технологии строительства и проектирования: новости, портфолио" name="description">
<meta content="строительство, проектирование, портфолио, новости" name="keywords">
<link href="../css/style.css?v=3" type="text/css" rel="stylesheet">
</head>
<body>
<center>
<table width="1004" border="0">
	<tbody><tr>
		<td colspan="4">
		</td>
	</tr>
	<tr>
		<td colspan="4">
			<table width="1004"><tbody><tr height="1"><td width="1004" bgcolor="#244aa7"></td></tr></tbody></table>
		</td>
	</tr>
	<tr>
		<td colspan="4">
            <?php
            include "../header.php";
            ?>
		</td>
	</tr>
	<tr>
		<td colspan="4">
            <?php
            include "admin_menu.php";
            ?>
		</td>
	</tr>
	<tr>
		<td style="height: 100%;" width="100">
		</td>
		<td width="900">
			<table class="main" border="0" width="90%" style="height:350px">
				<tbody>
				<tr>
                    <td style="text-align:center; vertical-align:middle;" align="center">
                        <span style="color:red;">
                            <b>
                                <?php print $resultMessage ?>
                            </b>
                        </span>
                        <br/>
                        <br/>
                        <form action="change_password.php" method="post">
                        <table width="450" align="center">
                            <tr>
                                <th style="text-align:right;">старый пароль</th>
                                <td>
                                    <input name="password0" type="password">
                                </td>
                            </tr>
                            <tr>
                                <th style="text-align:right;">новый пароль</th>
                                <td>
                                    <input name="password1" type="password">
                                </td>
                            </tr>
                            <tr>
                                <th style="text-align:right;">подтвердить новый пароль</th>
                                <td>
                                    <input name="password2" type="password">
                                </td>
                            </tr>
                            <tr>
                                <td></td>
                                <td align="center">
                                    <br/>
                                    <input type="submit" value="Изменить" align="middle">
                                </td>
                            </tr>
                        </table>
                        </form>
                    </td>
				</tr>
			</tbody></table>
		</td>
		<td width="0">
		</td>

	</tr>
	<tr>
		<td colspan="4">
            <?php
            include "../footer.php";
            ?>
		</td>
	</tr>
</tbody></table>
</center>

</body></html>